package dialog;

import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.TextView;

import com.example.zx.theline.jclr.JclrActivity;
import com.example.zx.theline.R;

import org.apache.http.Header;

import java.util.ArrayList;
import java.util.List;

import GsonBean.JcxxChakanBean;
import GsonBean.SuccessBean;
import GsonBean.post.ShcfPost;
import GsonBean.post.TjjdjcdPost;
import Utils.RefreshManager;
import app.MyApplication;
import base.BaseDialog;
import network.NetWorkApi;
import network.ObjectHttpResponseHandler;
import Utils.MyToast;
import retrofit2.Call;
import retrofit2.Callback;
import retrofit2.Response;

/**
 * Created by zx on 2017/4/17.
 */

public class ShcfDialog extends BaseDialog {

    //确定
    TextView queding;

    //取消
    TextView quxiao;

    ShcfPost mShcfPost;

    JcxxChakanBean mJcxxChakanBean;



    public ShcfDialog(Context context, JcxxChakanBean mJcxxChakanBean) {
        super(context);
        this.mJcxxChakanBean=mJcxxChakanBean;

    }


    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.dialog_shcf);
        InitData();
        InitView();
        InitListen();
    }

    @Override
    protected void InitView() {
        queding = (TextView) findViewById(R.id.queding);
        quxiao = (TextView) findViewById(R.id.quxiao);
    }

    @Override
    protected void InitData() {
        mShcfPost=new ShcfPost();
    }

    @Override
    protected void InitListen() {
        queding.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                MyApplication.ShowWaitDialog(getContext());
                mShcfPost.setJdjhjcbId(mJcxxChakanBean.getRjdjhjcbInfo().getJdjhjcbId());
                mShcfPost.setJcbstatus(mJcxxChakanBean.getRjdjhjcbInfo().getJcbstatus());
                //审核单位流转信息list
                List<TjjdjcdPost.LjyyxRjdjhjcbShdw> jcbShdwList=new ArrayList<TjjdjcdPost.LjyyxRjdjhjcbShdw>();
                TjjdjcdPost.LjyyxRjdjhjcbShdw shdw=new TjjdjcdPost.LjyyxRjdjhjcbShdw();
                shdw.setJdjhbBh(mJcxxChakanBean.getRjdjhjcbInfo().getRjdjhbBh());
                shdw.setDwId(MyApplication.getmLoginUser().getUserUnitId());
                shdw.setDwmc(MyApplication.getmLoginUser().getUserUnitName());
                shdw.setShrlogin(MyApplication.getmLoginUser().getUserDisplayName());
                shdw.setShrname(MyApplication.getmLoginUser().getTrueName());
                shdw.setShrphone(MyApplication.getmLoginUser().getUserMobilephone());
                jcbShdwList.add(shdw);
                mShcfPost.setJcbShdwList(jcbShdwList);

                NetWorkApi.shcf(mShcfPost, new Callback<SuccessBean>() {
                            @Override
                            public void onResponse(Call<SuccessBean> call, Response<SuccessBean> response) {
                                try {
                                    MyApplication.HideWaitDialog();
                                    SuccessBean mBean = response.body();
                                    if (mBean.getMsg().equals("success") && mBean.getCount() != 0) {
                                        MyToast.showToast("审核成功");
                                        RefreshManager.Jdjc.RefreshJdjclrxx();
                                        RefreshManager.Jdjc.RefreshJdjcdcl();
                                        RefreshManager.Jdjc.RefreshJdjcycl();
                                        ShcfDialog.this.dismiss();
                                        getContext().startActivity(new Intent(getContext(), JclrActivity.class));

                                    } else {
                                        MyToast.showToast("审核失败，请检查网络信息");
                                    }
                                } catch (Exception e) {
                                    MyToast.showFail();
                                }
                                MyApplication.HideWaitDialog();
                            }

                            @Override
                            public void onFailure(Call<SuccessBean> call, Throwable t) {
                                MyToast.showFail();
                            }
                        }
                );
            }
        });
            quxiao.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View v) {
                    ShcfDialog.this.dismiss();
                }
            });
    }



}
